import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  // 状态
  const token = ref('')
  const userInfo = ref({})
  const adminname = ref('')

  // actions
  function setToken(newToken) {
    token.value = newToken
  }

  function setUserInfo(info) {
    userInfo.value = info
    adminname.value = info.username || info.adminname // 支持两种可能的字段名
  }

  function clearUserInfo() {
    token.value = ''
    userInfo.value = {}
    adminname.value = ''
  }

  return {
    token,
    userInfo,
    adminname,
    setToken,
    setUserInfo,
    clearUserInfo
  }
}) 